home *** CD-ROM | disk | FTP | other *** search
/ The CICA Windows Explosion! / The CICA Windows Explosion! - Disc 1.iso / desktop / winmaze4.zip / PLOT3D.H < prev    next >
C/C++ Source or Header  |  1994-05-13  |  9KB  |  213 lines

  1. #ifndef PLOT3D_H
  2. #define PLOT3D_H
  3.  
  4. //      Objects instantiated from this class may be used to plot z=f(x,y) in
  5. // in three dimensions.
  6.  
  7. typedef struct
  8.           {
  9.             unsigned char base_z;    // '1' - normal, '2' -- highlight, or
  10.                                      // '3' -- don't display; external to plot.
  11.             unsigned char color;     // shade of gray for this quadrilateral.
  12.             float         x;         // coordinates of corner of this
  13.             float         y;         // quadrilateral.
  14.             float         z;
  15.             int           x_division_index;
  16.             int           y_division_index;
  17.           } corner_rec, *corner_rec_ptr;
  18. //     One of the many vertices of quadrilaterals composing the plot.
  19.  
  20. typedef struct
  21.           {
  22.             double x;
  23.             double y;
  24.             double z;
  25.           } vertex_rec;
  26. //     A point or vector.
  27.  
  28. typedef struct sort_bound
  29.           {
  30.             int  lower_x;
  31.             int  lower_y;
  32.             int  upper_x;
  33.             int  upper_y;
  34.           } sort_bound_rec;
  35.  
  36. typedef struct sort_stack
  37.           {
  38.             sort_bound_rec    bound;
  39.             struct sort_stack *previous;
  40.           } sort_stack_rec;
  41.  
  42. class plot3d
  43.   {
  44.     private:
  45.       void              adjust_perspective(void);
  46.                           // Make parallel lines running away from the viewer
  47.                           // appear to converge at the horizon.
  48.       double            aspect_ratio;
  49.       unsigned char     color_max;
  50.                           // Maximum shade of gray for a quadrilateral
  51.                           // (before adjusted between darkest_gray and
  52.                           // lightest_gray).
  53.       unsigned char     color_min;
  54.                           // Minimum shade of gray for a quadrilateral
  55.                           // (before adjusted between darkest_gray and
  56.                           // lightest_gray).
  57.       corner_rec        **corner;
  58.                           // Vertices of quadrilaterals composing the plot.
  59.       int               corner_allocated;
  60.                           // TRUE if "corner" is allocated.
  61.       double            cos_rotation;
  62.       double            cos_tilt;
  63.       int               darkest_gray;
  64.                           // This is the darkest shade of gray that will
  65.                           // actually be displayed (for parts that can be seen).
  66.       void              evaluate_and_transform(double (*f)(double,double),
  67.                          double x_min,double x_max,double y_min,double y_max,
  68.                          int num_x_divisions,int num_y_divisions,
  69.                          double rotation,double tilt,
  70.                          int (*external_to_plot)(double,double),
  71.                          int (*red)(double,double));
  72.                           // Computes the vertices, etc. for each quadrilateral
  73.                           // composing the plot.
  74.       vertex_rec        light;
  75.                           // Vector pointing to the source of light. 
  76.       int               lightest_gray; 
  77.                           // This is the lightest shade of gray that will
  78.                           // actually be displayed.
  79.       int               num_colors;
  80.                           // Colors 0 through num_colors-2 represent shades of
  81.                           // gray from black to white.  num_colors-1 represents
  82.                           // red and is (optionally) used to highlight areas.
  83.       int               num_x_divisions;
  84.                           // Number of divisions of the x-axis used to define
  85.                           // the quadrilaterals composing the plot.
  86.       int               num_y_divisions;
  87.                           // Number of divisions of the y-axis used to define  
  88.                           // the quadrilaterals composing the plot.
  89.       TPalette          *palette;
  90.       PALETTEENTRY      palette_entry [256];
  91.       double            pixels_per_unit;
  92.       char              prepare_plot_state;
  93.                           // Internal state of "prepare_plot".
  94.       int               plot_prepared;
  95.                           // TRUE if the last call to "prepare_plot" was
  96.                           // successful.
  97.       char              plot_state;
  98.                           // Internal state of "plot".
  99.       double            radians;
  100.       void              rearrange(int,int,int,int,int *,int *);
  101.                           // Called by "sort_back_to_front".
  102.       double            rotation;
  103.                           // Degrees the plot is rotated about the z-axis.
  104.       void              shade(void);
  105.                           // Computes the shade of gray for each quadrilateral
  106.                           // composing the plot.
  107.       double            sin_rotation;
  108.       double            sin_tilt;
  109.       void              sort_back_to_front();
  110.                           // The painter's algorithm is used; items farther
  111.                           // from the viewer are drawn earlier.
  112.       sort_stack_rec    *stacked_bound_head;
  113.       double            tilt;
  114.                           // Degrees the plot is tilted after it is rotated.
  115.       int               use_palette;
  116.       TFrameWindow      *window_ptr;
  117.       double            x;
  118.       double            y_center;
  119.       double            x_delta;
  120.       int               x_division_num;
  121.       double            x_eye;
  122.       double            x_corner_max;
  123.       double            y;
  124.       double            y_delta;
  125.       int               y_division_num;
  126.       double            y_offset;
  127.       double            y_corner_max;
  128.       double            y_corner_min;
  129.       double            z_center;
  130.       double            z_offset;
  131.       double            z_out_max;
  132.       double            z_corner_max;
  133.       double            z_corner_min;
  134.     public:
  135.                      plot3d(TFrameWindow *);
  136.  
  137.                      ~plot3d(void);
  138.  
  139.               char   plot(TRect ®ion_to_paint,int show_red,int only_plot_red,
  140.                double bias=1.0);
  141. //     This function returns 'S' if it is successful in generating the 3D plot.
  142. //  It returns 'C' if it should be called again (because more work must be done
  143. //  on the plot).  Otherwise, it returns 'F' indicating a failure.  Its
  144. //  parameters are as follow:
  145. //
  146. //           region_to_paint -- only points in this rectangle will be plotted.
  147. //
  148. //           show_red -- highlight quadrilaterals having each vertex flagged
  149. //      to be highlighted.  
  150. //
  151. //           only_plot_red -- only plot the quadrilaterals having each vertex
  152. //      flagged to be highlighted.
  153. //
  154. //           bias -- a positive number used to adjust the contrast.
  155. //
  156. // "prepare_plot" must be called before "plot", after which "plot" may be called
  157. // as many times as desired.
  158.  
  159.               char   prepare_plot(double (*f)(double,double),double x_min,
  160.                       double x_max,double y_min,double y_max,
  161.                       int (*external_to_plot)(double,double),
  162.                       int (*red)(double,double),int x_division_count,
  163.                       int y_division_count,double rotation_in_degrees,
  164.                       double tilt_in_degrees,double light_x,double light_y,
  165.                       double light_z);
  166. //     This function returns 'S' if it is successful in preparing the plot for
  167. //  generation.  It returns 'C' if it should be called again (because more work
  168. //  must be done).  Otherwise, it returns 'F' indicating a failure.  Its
  169. //  parameters are as follow:
  170. //
  171. //           f -- z=f(x,y), the function to be plotted.  Before the plot is
  172. //      tilted or rotated, the z-axis runs from the bottom to the top of the
  173. //      display, the y-axis runs from the left to the right of the display,
  174. //      and the x-axis runs out of the display.
  175. //
  176. //           x_min -- the minimum value of x to be plotted.
  177. //
  178. //           x_max -- the maximum value of x to be plotted.
  179. //
  180. //           y_min -- the minimum value of y to be plotted.
  181. //
  182. //           y_max -- the maximum value of y to be plotted.
  183. //
  184. //           external_to_plot -- a function that returns TRUE if and only if a
  185. //      point should be omitted from the plot.
  186. //
  187. //           red -- a function that returns TRUE if and only if a point should
  188. //      be flagged for highlighting.  A point should be so flagged only if it
  189. //      can be seen in the final plot.
  190. //
  191. //           x_division_count -- the number of x divisions to be used in
  192. //      constructing the plot.  At least two must be specified.
  193. //
  194. //           y_division_count -- the number of y divisions to be used in
  195. //      constructing the plot.  At least two must be specified.
  196. //
  197. //           rotation_in_degrees -- rotation (degrees) about an axis parallel to
  198. //      the z-axis and through the center of the surface.
  199. //
  200. //           tilt_in_degrees -- tilt (degrees) about an axis through the center
  201. //      of the surface and parallel to a line from the lower left hand corner of
  202. //      the display to the lower right hand corner of the display.  The plot is
  203. //      tilted after it is rotated.
  204. //
  205. //           (light_x,light_y,light_z) -- a vector pointing to the light source
  206. //      (at infinity).  The light source remains fixed while the plot is rotated
  207. //      or tilted.
  208.  
  209.               void   restart_plot(void);
  210.   };
  211.  
  212. #endif
  213.